/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package control_escolar;

import static control_escolar.inicio.constancia_inicio;
import static control_escolar.log.claves_sesion2;
import static control_escolar.log.expedientes;
import java.awt.Image;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author danielsaid
 */
public class Reporte_3 extends javax.swing.JFrame {

    /**
     * Creates new form Reporte_3
     */
    public Reporte_3() throws IOException {
        initComponents();
        setLocationRelativeTo(null);
        leerlineayllenarAlumnos();
        // setTableModel();
        semestre();
        parciales();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    public Image getIconImage() {
        Image retValue = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("umbrella-corp-2-icon.png"));
        return retValue;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        nom_alumno = new javax.swing.JTextField();
        num_exp = new javax.swing.JTextField();
        Regresar_repoerte3 = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        semestre_reporte3 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        parciales = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Calificaciones Parciales");
        setIconImage(getIconImage());
        setResizable(false);

        jLabel1.setText("Nombre del Alumno:");

        jLabel2.setText("No. de Exp:");

        jLabel3.setText("Semestre:");

        nom_alumno.setEnabled(false);

        num_exp.setEnabled(false);

        Regresar_repoerte3.setText("Regresar");
        Regresar_repoerte3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Regresar_repoerte3ActionPerformed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setText("Escuela Superior Big Citrus.");

        semestre_reporte3.setEnabled(false);

        parciales.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null, null}
            },
            new String [] {
                "Clave de Materia", "Nombre de Materia", "Parcial 1", "Parcial 2", "Parcial 3", "Parcial 4", "Calificacion", "Tipo de Evaluacion"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        parciales.setEnabled(false);
        jScrollPane1.setViewportView(parciales);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(339, 339, 339)
                                .addComponent(jLabel5))
                            .addGroup(layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(38, 38, 38)
                                        .addComponent(num_exp, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(38, 38, 38)
                                        .addComponent(semestre_reporte3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(37, 37, 37)
                                        .addComponent(nom_alumno, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(407, 407, 407)
                                .addComponent(Regresar_repoerte3)))
                        .addGap(0, 447, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addGap(4, 4, 4)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(nom_alumno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(num_exp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(16, 16, 16)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(semestre_reporte3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Regresar_repoerte3)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void Regresar_repoerte3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Regresar_repoerte3ActionPerformed
        // TODO add your handling code here:
        validando();
    }//GEN-LAST:event_Regresar_repoerte3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Reporte_3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Reporte_3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Reporte_3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Reporte_3.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new Reporte_3().setVisible(true);
                } catch (IOException ex) {
                    Logger.getLogger(Reporte_3.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Regresar_repoerte3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField nom_alumno;
    private javax.swing.JTextField num_exp;
    private javax.swing.JTable parciales;
    private javax.swing.JTextField semestre_reporte3;
    // End of variables declaration//GEN-END:variables

    public void leerlineayllenarAlumnos() {
        String EXP = Busqueda_reporte3.numex_alumno.getText();
        try {
            // Busqueda_reporte1 br1 = new Busqueda_reporte1();
            BufferedReader br = new BufferedReader(new FileReader("src/ArchivosTXT/Alumnos.txt"));
            String expediente;
            while ((expediente = br.readLine()) != null) {
//en line se pone la línea y haces lo que necesites con ella
                if (expediente.startsWith(EXP)) {
                    String[] alumno = expediente.split(";");
                    num_exp.setText(alumno[0]);
                    nom_alumno.setText(alumno[1] + " " + alumno[2] + " " + alumno[3]);

                }
            }
        } catch (IOException x) {
            x.printStackTrace();
        }
    }

    public void parciales() throws IOException {
        String EXP = Busqueda_reporte3.numex_alumno.getText();
        int o = 0;
        int a = 0;
        int b = 0;
        int c = 0;
        int q = 0;
        int e = 0;
        int k = 0;
        int g = 0;
        String expediente;
        try {         
            BufferedReader br = new BufferedReader(new FileReader("src/ArchivosTXT/Calificaciones.txt"));
            while ((expediente = br.readLine()) != null) {
                if (expediente.startsWith(EXP)) {
                    expediente = expediente.replace(EXP, "");
                    String[] horarios = expediente.split(";");
                    parciales.setValueAt(horarios[1], o, 0);
                    parciales.paintImmediately(parciales.getX(), parciales.getY(), parciales.getWidth(), parciales.getHeight());
                    o = o + 1;
                    parciales.setValueAt(horarios[2], a, 1);
                    parciales.paintImmediately(parciales.getX(), parciales.getY(), parciales.getWidth(), parciales.getHeight());
                    a = a + 1;
                    parciales.setValueAt(horarios[3], b, 2);
                    parciales.paintImmediately(parciales.getX(), parciales.getY(), parciales.getWidth(), parciales.getHeight());
                    b = b + 1;
                    parciales.setValueAt(horarios[4], c, 3);
                    parciales.paintImmediately(parciales.getX(), parciales.getY(), parciales.getWidth(), parciales.getHeight());
                    c = c + 1;
                    parciales.setValueAt(horarios[5], q, 4);
                    parciales.paintImmediately(parciales.getX(), parciales.getY(), parciales.getWidth(), parciales.getHeight());
                    q = q + 1;
                    parciales.setValueAt(horarios[6], e, 5);
                    parciales.paintImmediately(parciales.getX(), parciales.getY(), parciales.getWidth(), parciales.getHeight());
                    e = e + 1;
                    parciales.setValueAt(horarios[7], k, 6);
                    parciales.paintImmediately(parciales.getX(), parciales.getY(), parciales.getWidth(), parciales.getHeight());
                    k = k + 1;
                    parciales.setValueAt(horarios[8], g, 7);
                    parciales.paintImmediately(parciales.getX(), parciales.getY(), parciales.getWidth(), parciales.getHeight());
                    g = g + 1;

                }
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(kardex.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void semestre() throws IOException {
        String EXP = Busqueda_reporte3.numex_alumno.getText();
        int o = 0;
        int u = 0;
        int i = 0;
        int a = 0;
        int z = 0;
        String abecedario[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};

        String expediente;
        String nom_mat;
        String creditos;
        try {
//columna clave de la materia            
            BufferedReader clave = new BufferedReader(new FileReader("src/ArchivosTXT/Alta_Materia.txt"));
            while ((expediente = clave.readLine()) != null) {
                if (expediente.startsWith(EXP)) {
                    expediente = expediente.replace(EXP, "");
                    expediente = expediente.replace(";", "");
//columna nombre de la materia
                    BufferedReader nombre = new BufferedReader(new FileReader("src/ArchivosTXT/Materias.txt"));
                    nom_mat = expediente.trim();
                    while ((expediente = nombre.readLine()) != null) {
                        if (expediente.startsWith(nom_mat)) {
                            expediente = expediente.replace(nom_mat, "");
                            if (expediente.contains("30") || expediente.contains("20")) {
                                expediente = expediente.replace("30", "");
                                expediente = expediente.replace("20", "");
                                if (expediente.contains("01") || expediente.contains("02") || expediente.contains("03") || expediente.contains("04") || expediente.contains("05") || expediente.contains("06")) {
                                    expediente = expediente.replace("01", "");
                                }
                            }
                            expediente = expediente.replace(";", "");
                            creditos = expediente;
//columna creditos de la materia
                            BufferedReader credito = new BufferedReader(new FileReader("src/ArchivosTXT/Materias.txt"));
                            creditos = expediente;
                            while ((expediente = credito.readLine()) != null) {
                                if (expediente.startsWith(nom_mat)) {
                                    expediente = expediente.replace(nom_mat, "");
                                    if (expediente.contains(creditos)) {
                                        expediente = expediente.replace(creditos, "");
                                        if (expediente.contains("01") || expediente.contains("02") || expediente.contains("03") || expediente.contains("04") || expediente.contains("05") || expediente.contains("06") || expediente.contains("011")) {
                                            expediente = expediente.replace("01", "");
                                        }
                                    }
                                    expediente = expediente.replace(";", "");
//columna semestre de cada materia del archivo materias                                    
                                    BufferedReader semestre = new BufferedReader(new FileReader("src/ArchivosTXT/Materias.txt"));
                                    while ((expediente = semestre.readLine()) != null) {
                                        if (expediente.startsWith(nom_mat)) {
                                            expediente = expediente.replace(nom_mat, "");
                                            String[] semestre_al = expediente.split(";");
                                            semestre_reporte3.setText(semestre_al[3]);
                                            expediente = expediente.replace(";", "");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(kardex.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
   public void validando() {
        String EXP = log.expedientes.getText();
        String pwd = log.claves_sesion2.getText();
        if (expedientes.getText().length() != 0 && claves_sesion2.getText().length() != 0) {
            try {

                BufferedReader alumnos = new BufferedReader(new FileReader("src/ArchivosTXT/Alumnos.txt"));
                String Materias;
                while ((Materias = alumnos.readLine()) != null) {

                    if (Materias.startsWith(EXP)) {
                        String[] Al = Materias.split(";");
                        if (Al[0].equals(EXP) && Al[22].equals(pwd)) {
                            
                            new inicio().setVisible(true);
                            this.setVisible(false);
                            inicio.constancia_inicio.setVisible(false);
                            inicio.reporte1.setVisible(false);
                            inicio.reporte2.setVisible(true);
                            inicio.reporte3.setVisible(false);
                            inicio.kardex_inicio.setVisible(true);
                            inicio.jMenu2.setVisible(false);
                        } else {
                            JOptionPane.showMessageDialog(null, "Datos Erroneos");
                        }
                    }
                }

                BufferedReader maestros = new BufferedReader(new FileReader("src/ArchivosTXT/Maestros.txt"));
                String Maestros;
                while ((Maestros = maestros.readLine()) != null) {
                    if (Maestros.startsWith(EXP)) {
                        String[] Ma = Maestros.split(";");
                        if (Ma[0].equals(EXP) && Ma[12].equals(pwd)) {
                            
                            new inicio().setVisible(true);
                            this.setVisible(false);
                            inicio.constancia_inicio.setVisible(false);
                            inicio.reporte1.setVisible(false);
                            inicio.reporte2.setVisible(true);
                            inicio.reporte3.setVisible(false);
                            inicio.kardex_inicio.setVisible(false);
                            inicio.jMenu2.setVisible(true);
                            inicio.alumno_inicio.setVisible(false);
                            inicio.maestro_inicio.setVisible(false);
                            inicio.materia_inicio.setVisible(false);
                            inicio.Calificaciones.setVisible(true);
                            inicio.jMenuItem6.setVisible(false);
                            //inicio.jMenuItem7.setVisible(false);

                        } else {
                            JOptionPane.showMessageDialog(null, "Datos Erroneos");
                        }
                    }
                }
                if (EXP.equals("Admin") && pwd.equals("Citrus")) {
                    
                    new inicio().setVisible(true);
                    this.setVisible(false);
                    constancia_inicio.setVisible(true);
                    inicio.reporte1.setVisible(true);
                    inicio.reporte2.setVisible(true);
                    inicio.reporte3.setVisible(true);
                    inicio.kardex_inicio.setVisible(true);
                    inicio.jMenu2.setVisible(true);
                    inicio.alumno_inicio.setVisible(true);
                    inicio.maestro_inicio.setVisible(true);
                    inicio.materia_inicio.setVisible(true);
                    inicio.Calificaciones.setVisible(true);
                    inicio.jMenuItem4.setVisible(true);
                    inicio.jMenuItem6.setVisible(true);
                    inicio.jMenuItem7.setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(null, "Datos Erroneos");
                }
            } catch (IOException x) {
            }
        } else {
            JOptionPane.showMessageDialog(null, "Campos Requeridos");
        }
}

}
